package com.liangsui.mss.srevice.listener;

import com.liangsui.mss.constants.MQConstants;
import com.liangsui.mss.dto.CancelOrderMqDto;
import com.liangsui.mss.service.OrderChargeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * CancelPayOrderListener
 *
 * @author zhangjiawei
 * @email 1533167396@qq.com
 * @date 2022/12/8 20:10
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = MQConstants.Topic.CANCEL_PAY_ORDER, consumerGroup = "${rocketmq.producer.group}" + "_" + MQConstants.Topic.CANCEL_PAY_ORDER)
public class CancelPayOrderListener implements RocketMQListener<CancelOrderMqDto> {

    @Autowired
    private OrderChargeService orderChargeService;


    @Override
    public void onMessage(CancelOrderMqDto cancelOrderMqDto) {
        log.info("onMessage - data:{}", cancelOrderMqDto.getData());
        String orderId = cancelOrderMqDto.getData().getOrderId();
        orderChargeService.cancelPayOrder(orderId);
    }
}
